# -*- coding: utf-8 -*-
#pylint: disable-msg=E1101,W0212,W0232

# major - minor - tag - released
#
# $Revision: 245 $
# $Date: 2009-11-04 21:45:32 +0000 (Wed, 04 Nov 2009) $


__VERSION__ = (0, 3, 'rc', 2)
__REVISION__ = "$Revision: 245 $"

def __get_version():    
    def svn_version():
        import re
        rev_match = re.search('\$Revision: ([\d]*) \$', __REVISION__)
        if rev_match:
            return int(rev_match.groups()[0])
        return 0

    major, minor, tag, released = __VERSION__     
    build = svn_version()
    version = '%s.%s' % (major, minor )
    
    if tag == 'dev':
        version = '%s.dev.r%s' % ( version, build )    
    elif tag == 'rc':
        version = '%s%s' % ( version, tag)

    # put revision number if is a patch as post release number    
    if (released > 0) and tag in('rc','final'):
        version = '%s-%s' % ( version, build )
            
    return version

version = __get_version()

BASIC_TESTS = """
>>> import xadmin
>>> from xadmin import __get_version
>>> xadmin.__REVISION__ = '$ ' + '$Revision:'+' 111' +' $'
>>> xadmin.__VERSION__ = (0, 2, 'dev', 0); print __get_version()
0.2.dev.r111
>>> xadmin.__VERSION__ = (0, 2, 'dev', 1); print __get_version()
0.2.dev.r111
>>> xadmin.__VERSION__ = (0, 2, 'rc', 0); print __get_version()
0.2rc
>>> xadmin.__VERSION__ = (0, 2, 'rc', 1); print __get_version()
0.2rc-111
>>> xadmin.__VERSION__ = (0, 2, 'final', 0); print __get_version()
0.2
>>> xadmin.__VERSION__ = (0, 2, 'final', 1); print __get_version()
0.2-111
"""

__test__ = {'BASIC_TESTS': BASIC_TESTS,}

